/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.transl;

import java.util.ArrayList;
import java.util.List;

import alloy.bool.BooleanFormula;

/** Allocator of Boolean variables to relations. */
public class BoolVarAllocator {
    /** Number of boolean variables allocated so far.  {@link #allocRelation}
	allocates a continuous range of boolean variables to one relation. */
    private int numVarsAllocated = 0;

    /**
     * Constraints on the Boolean variables that we've allocated --
     * these will be conjoined with the final Boolean formula
     * before shipping it out to a SAT solver.
     */
    private List /* of BooleanFormula */ _varConstraints = new ArrayList();
    
    public int getNumAllocatedVars() { return numVarsAllocated; }
    public int allocBoolVar() { return ++numVarsAllocated; }

    /**
     * Constraints on the Boolean variables that we've allocated --
     * these will be conjoined with the final Boolean formula
     * before shipping it out to a SAT solver.
     */
    public BooleanFormula getVarConstraints() {
	return
	    BooleanFormula.makeAnd((BooleanFormula[])_varConstraints.toArray(new BooleanFormula[]{}));
    }

    public void addVarConstraint(BooleanFormula f_) { _varConstraints.add(f_); }
}
    
